﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using WalkingTec.Mvvm.Core;
using WalkingTec.Mvvm.Core.Extensions;
using Microsoft.EntityFrameworkCore;
using System.ComponentModel.DataAnnotations;
using HengTong.Model.Db;
using HengTong.Model.Db.System;
using TiaoTaoHelper.Wtm.Models;


namespace HengTong.ViewModel._Admin.SysUserJobPositionVms
{
    public partial class SysUserJobPositionListVm : BasePagedListVM<SysUserJobPositionView, SysUserJobPositionSearcher>
    {

        protected override IEnumerable<IGridColumn<SysUserJobPositionView>> InitGridHeader()
        {
            return new List<GridColumn<SysUserJobPositionView>>{
                this.MakeGridHeader(x => x.UserName),
                this.MakeGridHeader(x => x.JobPositionName),
                this.MakeGridHeader(x => x.IsMain),
                this.MakeGridHeaderAction(width: 200)
            };
        }

        public override IOrderedQueryable<SysUserJobPositionView> GetSearchQuery()
        {
            var query = DC.Set<SysUserJobPosition>()
                .CheckEqual(Searcher.UserId, x=>x.UserId)
                .CheckEqual(Searcher.JobPositionId, x=>x.JobPositionId)
                .CheckEqual(Searcher.IsMain, x=>x.IsMain)
                .Select(x => new SysUserJobPositionView
                {
				    ID = x.ID,
                    UserName = x.User.Name,
                    JobPositionName = x.JobPosition.Name,
                    IsMain = x.IsMain,
                })
                .OrderBy(x => x.ID);
            return query;
        }

    }

    public class SysUserJobPositionView : SysUserJobPosition{
        [Display(Name = "_Admin.Name")]
        public String UserName { get; set; }
        [Display(Name = "岗位名称")]
        public String JobPositionName { get; set; }

    }
}
